package com.guigu.tomcat.impl;

import com.guigu.tomcat.HttpServletRequest;
import com.guigu.tomcat.HttpServletResponse;
import com.guigu.tomcat.HttpSession;
import com.guigu.tomcat.ServletException;

import java.io.IOException;
import java.io.PrintWriter;

public class SessionServlet extends HttpServletImpl{

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        String name =request.getParameter("name");
        PrintWriter out = response.getWriter();
        HttpSession session=request.getSession();
        response.setContentType("text/html;charset=utf-8");
        if(name!=null){
            //保存在会话中
            session.setAttribute("name",name);
            out.println("<h1>请求参数值name :" +name+"</h1>");
        }else{
            name=(String) session.getAttribute("name");
            out.println("<h1>会话中的值name :" +name +"</h1>");
        }
    }

    @Override
    public void init() {

    }

    @Override
    public void destroy() {

    }
}
